/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pokemon.dto;

import com.pokemon.entities.Badge;
import com.pokemon.entities.Pokemon;
import com.pokemon.entities.Stadium;
import com.pokemon.entities.Trainer;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Martin Strasek
 */
public class DTOConvertor {
    
    public static Trainer dtoToEntity(TrainerDTO trainer) {
        Trainer tr = new Trainer();
        tr.setBirthDate(trainer.getBirthDate());
        tr.setFirstName(trainer.getFirstName());
        tr.setLastName(trainer.getLastName());
        tr.setId(trainer.getId());
        return tr;
    }
    public static Pokemon dtoToEntity(PokemonDTO pokemon) {
        Pokemon po = new Pokemon();
        po.setId(pokemon.getId());
        po.setName(pokemon.getName());
        po.setNickName(pokemon.getNickName());
        po.setReachedLevel(pokemon.getReachedLevel());
        if (pokemon.getTrainer() == null) {
            po.setTrainer(null);
        } else {
            po.setTrainer(dtoToEntity(pokemon.getTrainer()));
        }
        po.setType(pokemon.getType());
        return po;
    }
    
    public static Badge dtoToEntity(BadgeDTO badge) {
        Badge ba = new Badge();
        if (badge.getStadium() == null) {
            ba.setStadium(null);
        } else {
            ba.setStadium(dtoToEntity(badge.getStadium()));
        }
        if (badge.getTrainer() == null) {
            ba.setTrainer(null);
        } else {
            ba.setTrainer(dtoToEntity(badge.getTrainer()));
        }
        ba.setId(badge.getId());
        return ba;
    }
    
    public static Stadium dtoToEntity(StadiumDTO stadium) {
        Stadium st = new Stadium();
        st.setId(stadium.getId());
        st.setTown(stadium.getTown());
        if (stadium.getTrainer() == null) {
            st.setTrainer(null);
        } else {
            st.setTrainer(dtoToEntity(stadium.getTrainer()));
        }
        st.setType(stadium.getType());
        return st;
    }
    
    public static TrainerDTO entityToDto(Trainer trainer) {
        TrainerDTO tr = new TrainerDTO();
        tr.setBirthDate(trainer.getBirthDate());
        tr.setFirstName(trainer.getFirstName());
        tr.setLastName(trainer.getLastName());
        tr.setId(trainer.getId());
        return tr;
    }
    public static PokemonDTO entityToDto(Pokemon pokemon) {
        PokemonDTO po = new PokemonDTO();
        po.setId(pokemon.getId());
        po.setName(pokemon.getName());
        po.setNickName(pokemon.getNickName());
        po.setReachedLevel(pokemon.getReachedLevel());
        if (pokemon.getTrainer() == null) {
            po.setTrainer(null);
        } else {
            po.setTrainer(entityToDto(pokemon.getTrainer()));
        }
        po.setType(pokemon.getType());
        return po;
    }
    
    public static BadgeDTO entityToDto(Badge badge) {
        BadgeDTO ba = new BadgeDTO();
        if (badge.getStadium() == null) {
            ba.setStadium(null);
        } else {
            ba.setStadium(entityToDto(badge.getStadium()));
        }
        if (badge.getTrainer() == null) {
            ba.setTrainer(null);
        } else {
            ba.setTrainer(entityToDto(badge.getTrainer()));
        }
        ba.setId(badge.getId());
        return ba;
    }
    
    public static StadiumDTO entityToDto(Stadium stadium) {
        StadiumDTO st = new StadiumDTO();
        st.setId(stadium.getId());
        st.setTown(stadium.getTown());
        if (stadium.getTrainer() == null) {
            st.setTrainer(null);
        } else {
            st.setTrainer(entityToDto(stadium.getTrainer()));
        }
        st.setType(stadium.getType());
        return st;
    }
    
    public static List<TrainerDTO> trainerEntityListToDtoList(List<Trainer> trainers) {
        List<TrainerDTO> trDtoList = new ArrayList<TrainerDTO>();
        for (int i = 0; i<trainers.size(); i++) {
            trDtoList.add(entityToDto(trainers.get(i)));
        }
        return trDtoList;
    }
    
    public static List<Trainer> trainerDtoListToEntityList(List<TrainerDTO> trainers) {
        List<Trainer> trEntityList = new ArrayList<Trainer>();
        for (int i = 0; i<trainers.size(); i++) {
            trEntityList.add(dtoToEntity(trainers.get(i)));
        }
        return trEntityList;
    }
    
    public static List<PokemonDTO> pokemonEntityListToDtoList(List<Pokemon> pokemons) {
        List<PokemonDTO> poDtoList = new ArrayList<PokemonDTO>();
        for (int i = 0; i<pokemons.size(); i++) {
            poDtoList.add(entityToDto(pokemons.get(i)));
        }
        return poDtoList;
    }
    
    public static List<Pokemon> pokemonDtoListToEntityList(List<PokemonDTO> pokemons) {
        List<Pokemon> poDtoList = new ArrayList<Pokemon>();
        for (int i = 0; i<pokemons.size(); i++) {
            poDtoList.add(dtoToEntity(pokemons.get(i)));
        }
        return poDtoList;
    }
    
    public static List<BadgeDTO> badgeEntityListToDtoList(List<Badge> badges) {
        List<BadgeDTO> baDtoList = new ArrayList<BadgeDTO>();
        for (int i = 0; i<badges.size(); i++) {
            baDtoList.add(entityToDto(badges.get(i)));
        }
        return baDtoList;
    }
    
    public static List<Badge> badgeDtoListToEntityList(List<BadgeDTO> badges) {
        List<Badge> baEntityList = new ArrayList<Badge>();
        for (int i = 0; i<badges.size(); i++) {
            baEntityList.add(dtoToEntity(badges.get(i)));
        }
        return baEntityList;
    }
    
    public static List<StadiumDTO> stadiumEntityListToDtoList(List<Stadium> stadiums) {
        List<StadiumDTO> stDtoList = new ArrayList<StadiumDTO>();
        for (int i = 0; i<stadiums.size(); i++) {
            stDtoList.add(entityToDto(stadiums.get(i)));
        }
        return stDtoList;
    }
    
    public static List<Stadium> stadiumDtoListToEntityList(List<StadiumDTO> stadiums) {
        List<Stadium> stEntityList = new ArrayList<Stadium>();
        for (int i = 0; i<stadiums.size(); i++) {
            stEntityList.add(dtoToEntity(stadiums.get(i)));
        }
        return stEntityList;
    }
}